function  [] = expandFromPoint( inputFileName,sliceNumber,outputFileName)
%this function gets nii file and slice number, getting an mouse coordinate
%on the slice from the user and saves segmentation nii file of the area
%where the user cliced.

    %thresh hold for intersity neighborhood
    DIFF_FACTOR = 0.1;

    %load the nifti file and extract the relevant slice
    image = load_nifti(inputFileName);
    origSlice = image(:,:,sliceNumber);
    
    %display the slice and wait for click from the user
    %we normal the values of the displayed image in order to be able to see most of the image
    figure(1);
    imshow(origSlice./max(origSlice(:)));
    [x,y] = ginput(1);
    x = int32(x);
    y = int32(y);
    
    origGrayLevel = image(y,x,sliceNumber);
    %prepare the segmentation matrix
    TH = zeros(size(image));
    
    %mark color-related voxels with "1"
    TH(logical((origGrayLevel*(1-DIFF_FACTOR)<=image) & (origGrayLevel*(1+DIFF_FACTOR)>=image))) = 1;
    
    %mark the voxels that's in the connected component of the relevant
    %voxel with '1'
    CC = bwconncomp(TH,26);
    L = labelmatrix(CC);
    
    S = zeros(size(image));
    S(CC.PixelIdxList{L(y,x,sliceNumber)})=1;
  
    save_nifti(S,outputFileName,2);
    close(1);
end

